﻿<!--#include file="../inc/common.asp" -->
<%
    'response.AddHeader "Last-Modified", DateToGMT(Now())
    'response.Expires = 0
    'response.CacheControl = "no-cache"
  
    if not userObj.isAdmin then
        response.write "您没有权限"
        call closeDB()
        response.end
    end if    
    call OpenDB
%>
<HTML><HEAD><TITLE><%=hostTitle%></TITLE>
<META http-equiv=Content-Type content="text/html; charset=<%=DEFAULT_CHARSET%>">
<style type="text/css">
li {
	line-height: 200%;
	}
</style>	
</HEAD>
<BODY>
<div align=center>
<form name=form1 action=sql.asp method=post>
请输入sql:
<p><textarea name=sql cols=60 rows=5 ></textarea></p>
<p><input type=submit name=execute value=execute></p>
<a href="index.asp">返回</a>
</form>
<%    
    sub executeSql(sql)
        dim tmpConn
        if instr(1,sql,TBL_USER,1)>0 then
            set tmpConn = userConn
        else
            set tmpConn = conn
        end if    
        if instr(1,sql,"select",1)=1 then
            rs.open sql, tmpConn, 1, 1
            dim i, count
            response.write "<table border=1><tr>" & vbCrLf
            for i=0 to rs.fields.count-1
                response.write "<th>" & rs(i).name & "</th>" & vbCrLf
            next
            response.write "</tr>" & vbCrLf
            count = 0
            while not rs.eof and count<1000
                count = count+1
                response.write "<tr>" & vbCrLf
                for i=0 to rs.fields.count-1
                    response.write "<td>" & rs(i) & "&nbsp;</td>" & vbCrLf
                next
                response.write "</tr>" & vbCrLf
                rs.moveNext()
            wend    
            response.write "</table>" & vbCrLf
            if count=1000 then
                response.write "<p>查询结果大于1000条，其余部分不再显示，请缩小查询范围</p>"
            end if
        elseif sql<>"" then
            dim rows

            tmpConn.execute sql,rows,adCMDUnknown

            if rows<1 then
                response.write "<p>执行完毕，处理了0条记录</p>"
            else
                '刷新缓存
                call removeAllFromCache()
    
                response.write "<p>执行完毕，处理了" & rows & "条记录。缓存已经更新</p>"
            end if    
        end if    
        
        set tmpConn = nothing
    end sub
    
    if request("execute") = "execute" then
        sql = trim(request("sql"))
        response.write "<p>"& replace(replace(sql,"<","&lt;"),">","&gt;") &"</p>" 
        executeSql(sql)
    end if
%>
</div>
</BODY>
</html>
<!--#include file="../inc/end.asp" -->
